package com.igroupes.ovineherd.model.Style;

import cn.hutool.json.JSONObject;
import com.igroupes.ovineherd.exception.ModelException;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@EqualsAndHashCode(callSuper = true)
@Slf4j
@Data
@ToString(callSuper=true)
public class InputStyle extends BasicStyle {
    protected Integer maxLength = 0;
    protected String message;
    /**
     * 必须的 true 是 false 否
     */
    protected Boolean required = false;
    protected JSONObject validations = new JSONObject();
    protected JSONObject validationErrors = new JSONObject();

    protected InputStyle(){
        super();
    }
    protected InputStyle(String label,Object value,Boolean required) {
        super(label, value);
        this.required = required;
        this.message = "必传字段";
    }

    @Override
    public Boolean verify(Object o) {
        super.verify(o);
        InputStyle inputStyle = (InputStyle) o;
        if(!(inputStyle.getMaxLength() instanceof Integer)){
            log.error("maxLength传值类型错误, {}", o);
            throw new ModelException("maxLength传值类型错误");
        }
        return true;
    }
}
